package 贪心;

/**
 * @author aodre , QQ : 480029069
 * @date 2022/12/24 10:30
 */
public class leetcode1754mergeMaxString {

    /*
     这个题  可以 有很多的想法在里面
     可以写的在简洁 一些
     */


    public String solution(String s1,String s2){
        int len1 = s1.length();
        int len2 = s2.length();
        int i = 0, j = 0;
        StringBuilder sb = new StringBuilder(len1 + len2);
        while(i < len1 && j < len2){
            char c1 = s1.charAt(i),c2 = s2.charAt(j);
            if(c1 == c2){
                sb.append(s1.substring(i).compareTo(s2.substring(j)) > 0 ? s1.charAt(i++) : s2.charAt(j++));
            }
            else if(c1 >  c2){
                i++;
                sb.append(c1);
            }
            else{
                sb.append(c2);
                j++;
            }

        }
        if(i < len1)
            sb.append(s1.substring(i));
        if(j < len2)
            sb.append(s2.substring(j));
        return sb.toString();
    }

}
